const express = require('express');
const app = express();
const server = require('http').createServer(app);
const socket = require('socket.io')(server);

//监听客户端链接,回调函数会传递本次链接的socket
socket.on('connection', socket => {
  // 监听客户端发送的信息
  socket.on("sentToServer", message => {
    // 给客户端返回信息
    socket.emit("sendToClient", {
      message
    });
  });
});

// 监听连接断开事件
socket.on("disconnect", () => {
  console.log("连接已断开...");
});

server.listen(9092);
